﻿
using BestTrader.Cms.ViewModels;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BestTrader.Cms.Core.Extensions;

namespace BestTrader.Cms.Admin.Validation
{
    public class ManagerAgentRegisterValidation : AbstractValidator<ManagerAgentRegisterModel>
    {
        public ManagerAgentRegisterValidation()
        {
            RuleFor(x => x.UserName).NotEmpty().Length(5, 32).WithMessage("登录名必须为5~32个字符");
            //RuleFor(x => x.RoleId).NotNull().WithMessage("用户所属角色不能为空") ;
            
            RuleFor(x => x.Mobile).Must(IsMobile).WithMessage("手机号码格式不正确");
            RuleFor(x => x.AuditImages).NotNull().WithMessage("用户图片资料不能为空");
            RuleFor(x => x.BankType).NotEqual("开户银行").WithMessage("请选择相关的开户银行");
            RuleFor(x => x.BankCard).Length(10, 32).WithMessage("银行卡号长度不能超过32个字符");
        }

        private bool IsEmail(string arg)
        {
            if (arg.IsNullOrWhiteSpace())
            {
                return true;
            }
            if (arg.IsEmail())
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private bool IsMobile(string arg)
        {
            if (arg.IsNullOrWhiteSpace())
            {
                return true;
            }
            if (arg.IsMobileNumber())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
